﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

using CSF.Utility.Mvc;
using CSF.Service.Accounts.Client;
using CSF.Security.Data;
using CSF.Utility.Misc;

namespace CSF.WebApp.Admin.Areas.Users.Controllers
{
    public class UserLogController : SecureController
    {
        /// <summary>
        /// author:andy-peng
        ///date:2011-08-23
        ///User Session
        /// </summary>
        /// <returns></returns>

        public ActionResult UserSession()
        {
            UserSessionSvcClient svc = new UserSessionSvcClient();
            IEnumerable<UserSession> list = null;
            list = svc.GetAll();
            list = Search(list);
            return View(list);

        }

        /// <summary>
        /// author:andy-peng
        /// date:2011-08-23
        /// 日志列表搜索
        /// </summary>
        /// <param name="isDisable"></param>
        /// <returns></returns>
        [NonAction]
        private IEnumerable<UserSession> Search(IEnumerable<UserSession> list)
        {
            var collection = Request.QueryString;
            var username = collection["UserName"];
            if (!string.IsNullOrWhiteSpace(username))
            {
                list = list.Where(p => username.InStr(p.UserName));
            }
            return list;
        }

        /// <summary>
        /// author:andy-peng
        /// date:2011-08-23
        /// 操作日志列表
        /// </summary>
        /// <param name="isDisable"></param>
        /// <returns></returns>
        public ActionResult UserActionLog()
        {
            UserActionLogSvcClient svc = new UserActionLogSvcClient();
            IEnumerable<UserActionLog> list = null;
            list = svc.GetAll();
            list = SearchActionLog(list);
            return View(list);

        }

        /// <summary>
        /// author:andy-peng
        /// date:2011-08-23
        /// 操作日志列表搜索
        /// </summary>
        /// <param name="isDisable"></param>
        /// <returns></returns>
        [NonAction]
        private IEnumerable<UserActionLog> SearchActionLog(IEnumerable<UserActionLog> list)
        {
            var collection = Request.QueryString;
            var username = collection["UserName"];
            if (!string.IsNullOrWhiteSpace(username))
            {
                list = list.Where(p => username.InStr(p.UserName));
            }
            return list;
        }
    }
}
